package top.ffhome.system.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import top.ffhome.common.page.PageRequest;
import top.ffhome.common.result.Result;
import top.ffhome.system.service.SysLoginLogService;

@CrossOrigin
@RestController
@RequestMapping("api/log/login")
@Api(tags = "系统登录日志控制器")
public class SysLoginLogController {
	@Autowired
	private SysLoginLogService loginLogService;

	@RequiresPermissions("system:loginlog:remove")
	@PostMapping("/delete")
	@ApiOperation("删除登录日志")
	@ApiImplicitParams(@ApiImplicitParam(name = "ids", value = "需删除的ID", required = true, paramType = "body", allowMultiple = true, dataType = "Long"))
	public Result delete(@RequestBody List<Long> ids) {
		loginLogService.delete(ids);
		return Result.success();
	}

	@RequiresPermissions("system:loginlog:clean")
	@GetMapping("/clean")
	@ApiOperation("清空登录日志")
	public Result clean() {
		loginLogService.clean();
		return Result.success();
	}

	@RequiresPermissions("system:loginlog:view")
	@PostMapping("/findPage")
	@ApiOperation("登录日志分页列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "params.accountLike", value = "账号模糊搜索", dataType = "String", paramType = "body"),
			@ApiImplicitParam(name = "params.userNameLike", value = "用户名模糊查询", dataType = "String", paramType = "body"),
			@ApiImplicitParam(name = "params.browserLike", value = "浏览器名称模糊查询", dataType = "String", paramType = "body"),
			@ApiImplicitParam(name = "params.osLike", value = "操作系统名称模糊查询", dataType = "String", paramType = "body"),
			@ApiImplicitParam(name = "params.loginTimeGte", value = "登录时间开始", dataType = "Date", paramType = "body"),
			@ApiImplicitParam(name = "params.loginTimeLte", value = "登录时间结束", dataType = "Date", paramType = "body") })
	public Result findPage(@RequestBody PageRequest request) {
		return Result.success(loginLogService.select(request));
	}
}
